# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/20 下午5:37
 @Author  : tgy
 
"""
import operator
import sys

class Attrgetter:
    ...
    __slots__ = ['_attrs', '_call']

    def __init__(self, attr, *attrs):
        ...
        if not attrs:

            if not isinstance(attr,str):
                raise TypeError('attr must str')
            self._attrs = (attr,)
            def func(obj):
                names = attr.split('.')
                for name in names:
                    obj = getattr(obj, name)
                return obj

            self._call = func
        else:
            ...
            self._attrs = (attr,) + attrs
            def func(obj):
                ...
                # getters = (Attrgetter(att) for att in self._attrs)
                getters = tuple(map(Attrgetter,self._attrs))
                return tuple(getter(obj) for getter in getters)
            self._call = func

    def __call__(self, obj):
        return self._call(obj)


class Dog:
    __slots__ = ['_name']

    def __init__(self,name):
        self._name = name


class Person:

    __slots__ = ['_dog','_name']

    def __init__(self, dog):
        self._dog = dog
        self._name = 'tony'



if __name__ == '__main__':
    ...
    print('111.111'.split('.'))
    attrgetter = Attrgetter('_dog._name','_name')
    p1 = Person(Dog('旺财'))
    print(attrgetter(p1))
    a,*b = 'zhangsam'
    print(type(b),file=sys.stderr)
    names = ['aa',
             'bb',
             'ccc'
             ]
    print(names)